package com.tanhua.server.controller;

import com.tanhua.model.vo.QuestionnaireVo;
import com.tanhua.model.vo.SoulResultVo;
import com.tanhua.server.service.SoulService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author lamy
 * @version 1.0
 * @ClassName: SoulController
 * @date 2021-12-26 20:13:47
 */
@RestController
@RequestMapping("/testSoul")
public class SoulController {
    @Autowired
    private SoulService soulService;

    /**
     * 测灵魂-问卷列表
     * @return
     */
    @RequestMapping(method = RequestMethod.GET)
    public ResponseEntity findQuestionNaire() {
        List<QuestionnaireVo> list = soulService.findQuestionNaire();
        return ResponseEntity.ok(list);
    }

    /**
     * 测灵魂-提交问卷
     * @return
     */
    @RequestMapping(method = RequestMethod.POST)
    public ResponseEntity submitQuestionNaire(@RequestBody Map answers){
        List<Map<String, String>> hashMaps= (List<Map<String, String>>) answers.get("answers");
        String id = soulService.submitQuestionNaire(hashMaps);
        return ResponseEntity.ok(id);
    }

    /**
     * 测灵魂-查看结果
     * @param id 报告id
     * @return
     */
    @RequestMapping(value = "/report/{id}",method = RequestMethod.GET)
    public ResponseEntity soulResult(@PathVariable Long id){
        SoulResultVo soulResultVo = soulService.soulResult(id);
        return ResponseEntity.ok(soulResultVo);
    }
}
